Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

[dev] reconnect socket after bad protocol message #1276

Merged
merged 4 commits into from
May 15, 2020

Conversation

EverlastingBugstopper
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper commented May 12, 2020

fixes #1241

after a while, the preview service disconnects the websocket, even if you're being a good citizen and sending keep alive heartbeat messages every now and then. for shame! after merging this if your dev session gets disconnected from the websocket we'll issue a reconnect. :) :) :)

@EverlastingBugstopper EverlastingBugstopper marked this pull request as draft May 12, 2020 15:28
@EverlastingBugstopper
Copy link
Contributor Author

getting a pretty opaque compiler error that i'm not sure how to resolve..

error: future cannot be sent between threads safely
   --> src/commands/dev/socket.rs:59:23
    |
59  |         let printer = tokio::spawn(print_ws_messages(Arc::clone(&passable_read)))
    |                       ^^^^^^^^^^^^ future returned by `print_ws_messages` is not `Send`
    | 
   ::: /Users/averyharnish/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.20/src/task/spawn.rs:127:21
    |
127 |         T: Future + Send + 'static,
    |                     ---- required by this bound in `tokio::task::spawn::spawn`
    |
    = help: within `impl core::future::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, futures_util::stream::stream::split::SplitStream<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream, tokio_tls::TlsStream<tokio::net::tcp::stream::TcpStream>>>>>`
note: future is not `Send` as this value is used across an await
   --> src/commands/dev/socket.rs:77:31
    |
76  |     let mut read = read.lock().unwrap();
    |         -------- has type `std::sync::MutexGuard<'_, futures_util::stream::stream::split::SplitStream<tokio_tungstenite::WebSocketStream<tokio_tungstenite::stream::Stream<tokio::net::tcp::stream::TcpStream, tokio_tls::TlsStream<tokio::net::tcp::stream::TcpStream>>>>>` which is not `Send`
77  |     while let Some(message) = read.next().await {
    |                               ^^^^^^^^^^^^^^^^^ await occurs here, with `mut read` maybe used later
...
94  | }
    | - `mut read` is later dropped here

i want an async fn that i can spawn and then try_join

and if an error occurs in either of the futures i've spawned (keep_alive messages and printing incoming socket messages) i want to kill the futures i've spawned and start my listen fn over from the beginning

@EverlastingBugstopper EverlastingBugstopper force-pushed the avery/re-connect-socket branch 2 times, most recently from a6652a3 to 0394c28 Compare May 13, 2020 19:21
@EverlastingBugstopper EverlastingBugstopper requested a review from a team May 14, 2020 16:02
@EverlastingBugstopper EverlastingBugstopper self-assigned this May 14, 2020
@EverlastingBugstopper EverlastingBugstopper marked this pull request as ready for review May 14, 2020 16:03
@EverlastingBugstopper EverlastingBugstopper changed the title wip reconnect socket after bad protocol message [dev] reconnect socket after bad protocol message May 14, 2020
src/commands/dev/socket.rs Outdated Show resolved Hide resolved
src/commands/dev/socket.rs Outdated Show resolved Hide resolved
src/commands/dev/socket.rs Outdated Show resolved Hide resolved
@EverlastingBugstopper
Copy link
Contributor Author

@ObsidianMinor thanks so much for the review 😄

@EverlastingBugstopper EverlastingBugstopper merged commit b0f43b0 into master May 15, 2020
@delete-merged-branch delete-merged-branch bot deleted the avery/re-connect-socket branch May 15, 2020 18:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dev] Rust panics after inactivity "Connection reset without closing handshake"
3 participants